package _18_剑指OfferII;

public class _091_剑指OfferII粉刷房子 {

    public int minCost(int[][] costs) {
        int len = costs.length;

        int red = costs[0][0];
        int blue = costs[0][1];
        int green = costs[0][2];
        for (int i = 1; i < len; i++) {
            int tempRed = red;
            int tempBlue = blue;
            int tempGreen = green;
            red = Math.min(tempBlue + costs[i][0], tempGreen + costs[i][0]);
            blue = Math.min(tempRed + costs[i][1], tempGreen + costs[i][1]);
            green = Math.min(tempRed + costs[i][2], tempBlue + costs[i][2]);
        }
        return Math.min(Math.min(red, blue), green);
    }

}
